package com.cet.algorithm.贪心算法.跳跃游戏;

/**
 * @program: cet-practice
 * @description: 跳跃游戏
 * @author: 陈恩涛
 * @create: 2023-06-07 23:05
 **/
public class LC55 {

    /**
     * 数组中元素为最远跳跃的长度
     * @param nums
     * @return
     */
    public boolean canJump(int[] nums) {

        int coveredTarget = 0;

        for (int i = 0; i <= coveredTarget; i++) {
            coveredTarget = Math.max(coveredTarget, i + nums[i]);
            if (coveredTarget >= nums.length - 1) {
                return true;
            }
        }

        return false;
    }

    public static void main(String[] args) {
        LC55 lc55 = new LC55();
        System.out.println(lc55.canJump(new int[]{2, 5, 0, 0}));
    }
}
